/**
 * Created by End on 2018/10/25.
 */
function $(id) {
	return document.getElementById(id);
}

function userNameBlur() {
	var username = $("username");
	var check_name = $("check_name");
	var reg = /^[0-9a-zA-Z][0-9a-zA-Z_.-]{2,16}[0-9a-zA-Z]$/;
	if (username.value == "") {
		check_name.innerHTML = "<img src='images/error.png' style='width:2rem;height:2rem;padding-top: 0.5rem'>";
		return false;
	} else if (reg.test(username.value) == false) {
		check_name.innerHTML = "<img src='images/error.png' style='width:2rem;height:2rem;padding-top: 0.5rem'>";
		return false;
	} else {
		check_name.innerHTML = "<img src='images/right.png' style='width:2rem;height:2rem;padding-top: 0.5rem'>";
		return true;
	}
}
function phoneBlur() {
	var phone = $("phone");
	var check_phone = $("check_phone");
	var reg = /^(13|15|18)\d{9}$/;
	if (phone.value == "") {
		check_phone.innerHTML = "<img src='images/error.png' style='width:2rem;height:2rem;padding-top: 0.5rem'>";
		return false;
	} else if (reg.test(phone.value) == false) {
		check_phone.innerHTML = "<img src='images/error.png' style='width:2rem;height:2rem;padding-top: 0.5rem'>";
		return false;
	} else {
		check_phone.innerHTML = "<img src='images/right.png' style='width:2rem;height:2rem;padding-top: 0.5rem'>";
		return true;
	}
}
//function check_identify(checkcode) {// 判断验证码是否正确
//	var identify = $("identify");
//	var check_img = $("check_img");
//	var img = $("img");
//	alert(checkcode);
//	if (identify.value == "") {
//		check_img.innerHTML = "<img src='images/error.png' style='width:2rem;height:2rem;padding-top: 0.5rem'>";
//		return false;
//	} else if(identify.value == checkcode){
//		check_img.innerHTML = "<img src='images/right.png' style='width:2rem;height:2rem;padding-top: 0.5rem'>";
//		return true;
//	} else {
//		check_img.innerHTML = "<img src='images/error.png' style='width:2rem;height:2rem;padding-top: 0.5rem'>";
//		return false;
//	}
//}
function form_is_valid() {
	var userFlag = userNameBlur();
	var phoneFlag = phoneBlur();
	var checkcode = check_identify();
	if (checkcode == false) {
		alert("验证码输入错误！");
	} else {
		if (userFlag == true && phoneFlag == true) {
			return true;
		} else if (userFlag == false && phoneFlag == true) {
			alert("用户名输入有误，请重新输入！");
			return false;
		} else if (userFlag == true && phoneFlag == false) {
			alert("手机号码输入有误，请重新输入！");
			return false;
		} else {
			alert("输入有误，请重新输入");
			return false;
		}
	}
}

function showTime()
{
	var time=60;
    var btn=$("btn1");
    var timer=setInterval(function () {
        if(time<=0)
        {
            btn.removeAttribute("disabled");
            btn.innerHTML="重新发送";
            time=60;
            clearInterval(timer);
        }
        else
        {
            btn.disabled=true;
            btn.innerHTML=time+"s后可重新发送"
            time--;
        }
    },1000);
}

